cmake_minimum_required(VERSION 3.10.2)
project(infer)

set(CMAKE_CXX_STANDARD 17)

find_package(CUDA)
MESSAGE("CUDA_DIR : ${CUDA_INCLUDE_DIRS}")

find_package(OpenCV REQUIRED)##查找opencv

message(STATUS "OpenCV library status:")
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")

set(TENSORRT_DIR "/opt/TensorRT-8.5.1.7")
find_library(TENSORRT_LIBRARY NAMES nvinfer HINTS "${TENSORRT_DIR}/lib")
find_path(TENSORRT_INCLUDE_DIR NAMES NvInfer.h HINTS "${TENSORRT_DIR}/include")
message("tensorrt version ${TensorRt_VERSION}")

INCLUDE_DIRECTORIES(
        ${CUDA_INCLUDE_DIRS}
        ${OpenCV_INCLUDE_DIRS}
        ${TENSORRT_INCLUDE_DIR}
)

file(GLOB SOURCES "util/*.h" "util/*.cu")
MESSAGE('${SOURCES}')
cuda_add_executable(infer main.cpp ${SOURCES})

target_link_libraries(infer ${CUDA_LIBRARIES} -lcuda)
target_link_libraries(infer ${OPENCV_INCLUDE_DIRS})#将库链接到文件中
target_link_libraries(infer ${OpenCV_LIBS})
target_link_libraries(infer ${TENSORRT_LIBRARY})


# C++ 的解决办法
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -finput-charset=UTF-8 -fexec-charset=UTF-8")
